package com.ruoyi.web.controller.hospitals;


import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hospital.service.HospitalsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.Hospitals;

import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医院信息Controller
 *
 * @author ruoyi
 * @date 2025-06-27
 */
@RestController
@RequestMapping("/hospitals/hospitals")
public class HospitalsController extends BaseController
{
    @Autowired
    private HospitalsService hospitalsService;

    /**
     * 查询医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:getAllHospitals')")
    @GetMapping("/getAllHospitals")
    public AjaxResult getAllHospitals(Hospitals hospitals)
    {
       return success(hospitalsService.list());
    }

    /**
     * 查询医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:list')")
    @GetMapping("/list")
  public TableDataInfo list(Hospitals hospitals)
  {
      List<Hospitals> list = hospitalsService.selectHospitalsList(hospitals);
      return getDataTable(list);
  }

    /**
     * 导出医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:export')")
    @Log(title = "医院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hospitals hospitals)
    {
        List<Hospitals> list = hospitalsService.selectHospitalsList(hospitals);
        ExcelUtil<Hospitals> util = new ExcelUtil<Hospitals>(Hospitals.class);
        util.exportExcel(response, list, "医院信息数据");
    }

    /**
     * 获取医院信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") String hospitalId)
    {
        return success(hospitalsService.getById(hospitalId));
    }

    /**
     * 新增医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:add')")
    @Log(title = "医院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hospitals hospitals)
    {

        return toAjax(hospitalsService.savehospitals(hospitals));
    }

    /**
     * 修改医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hospitals hospitals)
    {
        return toAjax(hospitalsService.updateById(hospitals));
    }

    /**
     * 删除医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospitals:hospitals:remove')")
    @Log(title = "医院信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable List<String> hospitalIds)
    {
        //数组改成集合
//                List<Long> list=Arrays.asList(hospitalIds);
        return toAjax(hospitalsService.removeByIds(hospitalIds));
    }
}
